package classfile

type InnerClassesAttr struct {
	AttrStruct
	numberOfClasses uint16
	classList       []InnerClass
}

type InnerClass struct {
	InnerClassInfoIndex   uint16
	OuterClassInfoIndex   uint16
	InnerNameIndex        uint16
	innerClassAccessFlags uint16
}

func (self *InnerClassesAttr) readAttrInfo(cp ConstantPool) AttributeInfo {
	self.numberOfClasses = self.attributeData.ReadUInt16()
	if self.numberOfClasses > 0 {
		self.classList = make([]InnerClass, self.numberOfClasses)
		for i := 0; i < int(self.numberOfClasses); i++ {
			self.classList[i] = NewInnerClass(&self.attributeData, cp)
		}
	}
	return self
}

func NewInnerClass(data *AttributeData, cp ConstantPool) InnerClass {
	ic := &InnerClass{}
	ic.InnerNameIndex = data.ReadUInt16()
	ic.OuterClassInfoIndex = data.ReadUInt16()
	ic.InnerClassInfoIndex = data.ReadUInt16()
	ic.innerClassAccessFlags = data.ReadUInt16()
	return *ic
}
